package com.ankicoo.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Description: 字符串操作工具类
 *
 * @author : QCYANG
 * @date : 2021/1/21 16:28
 */
public class StringUtil {

    /**
     * 检索特定字符串在目标字符串中出现次数
     * @param sourceStr 被检索源
     * @param findStr 检索目标
     * @return 出现次数
     */
    public static int strOccurTimes(String sourceStr, String findStr) {
        int count = 0;
        Pattern p = Pattern.compile(findStr);
        Matcher m = p.matcher(sourceStr);
        while (m.find()) {
            count++;
        }
        return count;
    }
}
